//
//  UIImage+ext.swift
//  EPHome
//
//  Created by liujianlong on 2022/8/1.
//

import UIKit


extension UIImage
{
    class func withURL(_ url:String)->UIImage
    {
        let data = NSData(contentsOf: URL(string:url)!)! as Data
        return UIImage.sd_image(with:data)!
    }
    
    class func withColor(_ color:UIColor)->UIImage
    {
        let rect = CGRect(x:0, y:0, width:10.0, height: 10.0)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context?.setFillColor(color.cgColor)
        context?.fill(rect)
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img!
    }
    
    func base64()->String
    {
        let data = self.jpegData(compressionQuality:1.0)
        return data!.base64EncodedString(options:.endLineWithCarriageReturn)
    }
}
